package org.chipu.jnids.sce.profile;

import java.util.*;
import java.util.Map.Entry;

/** A wrapper around all the available stats in a single instant */
public final class PuntualStats implements Iterable<Map.Entry<StatType, Stats>> {
	public final long timeUTC;
	private final Map<StatType, Stats> map = new HashMap<StatType, Stats>();

	public PuntualStats(long timeInMillis) {
		timeUTC = timeInMillis;
	}

	public void add(StatType type, Stats stats) {
		if (stats == null || stats.isEmpty())
			return;
		try {
			map.put(type, stats);
		} catch(NullPointerException ex) {
			System.err.println("Wrong arguments: " + type + "    " + stats);
			throw ex;
		}
	}

	public Stats get(StatType type) {
		return map.get(type);
	}

	@Override
	public Iterator<Entry<StatType, Stats>> iterator() {
		return map.entrySet().iterator();
	}

	@Override
	public String toString() {
		return "PuntualStats[time=" + new Date(timeUTC) + ",stats(" + map.size() + ")=" + map + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || !obj.getClass().isAssignableFrom(getClass()))
			return false;
		PuntualStats o = (PuntualStats) obj;
		return timeUTC == o.timeUTC && map.equals(o.map);
	}
	
	public boolean isEmpty() {
		return map.isEmpty();
	}
}